package com.frame.base;

import com.frame.para.ParametersUtil;
import com.frame.servlet.HttpServletUtil;
import eu.bitwalker.useragentutils.Browser;
import eu.bitwalker.useragentutils.UserAgent;
import eu.bitwalker.useragentutils.Version;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class BaseController {

	protected HttpServletRequest  request;
	protected HttpServletResponse response;

	/**
	 * @author Flying
	 * @param request
	 * @param response
	 */
	@ModelAttribute
	protected void inio(HttpServletRequest request,HttpServletResponse response){
		this.request = request;
		this.response = response;
//		 请求到达之前操作用户认证
	}
	
	
	/**
	 * 获取请求者IP
	 * @param
	 * @author Flying
	 * @return
	 */
	protected  String getIpAddr() {
	        return HttpServletUtil.getRequestIp(this.request);
	    }

	/**
	 * description:获取浏览器版本号
	 * @author: dove king
	 * @date: 11:21 2018/5/3
	 * @param:[request]
	 * @return java.lang.String
	 */
	protected String getBrowser(){
		//获取浏览器信息
		Browser browser = UserAgent.parseUserAgentString(request.getHeader("User-Agent")).getBrowser();
		//获取浏览器版本号
		Version version = browser.getVersion(request.getHeader("User-Agent"));
		String info = "";
		if(!ParametersUtil.isNull(version)){
			info = browser.getName() + "/" + version.getVersion();
		}
		if("".equals(info)){
			info="Robot";
		}
		return info;
	}




}